Before working on this assignment please read these instructions fully. In the submission area, you will notice that you can click the link to Preview the Grading for each step of the assignment. This is the criteria that will be used for peer grading. Please familiarize yourself with the criteria before beginning the assignment.
An NOAA dataset has been stored in the file data/C2A2_data/BinnedCsvs_d400/fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89.csv
. This is the dataset to use for this assignment. Note: The data for this assignment comes from a subset of The National Centers for Environmental Information (NCEI) Daily Global Historical Climatology Network (GHCN-Daily). The GHCN-Daily is comprised of daily climate records from thousands of land surface stations across the globe.
Each row in the assignment datafile corresponds to a single observation.
The following variables are provided to you:
For this assignment, you must:
The data you have been given is near Ann Arbor, Michigan, United States, and the stations the data comes from are shown on the map below.
import matplotlib.pyplot as plt
import mplleaflet
import pandas as pd
def leaflet_plot_stations(binsize, hashid):
df = pd.read_csv('data/C2A2_data/BinSize_d{}.csv'.format(binsize))
station_locations_by_hash = df[df['hash'] == hashid]
lons = station_locations_by_hash['LONGITUDE'].tolist()
lats = station_locations_by_hash['LATITUDE'].tolist()
plt.figure(figsize=(8,8))
plt.scatter(lons, lats, c='r', alpha=0.7, s=200)
return mplleaflet.display()
leaflet_plot_stations(400,'fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89')
get_ipython().magic('matplotlib notebook')
import pandas as pd
import numpy as np
import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib.ticker import FormatStrFormatter
data = pd.read_csv('data/C2A2_data/BinnedCsvs_d25/391a2922ad597ba080f4b99dea6d62842562d64845ef5df1a384561e.csv')
data["Data_Value"] = data['Data_Value'].div(10)
data2015 = data.where(data['Date'].str.contains('2015')).dropna()
data2015['Date'] = data2015.Date.str[5:]
data['Date'] = data.Date.str[5:]
# Skip leap days
data = data.where(data['Date'] != '02-29')
# Find record highs and lows
record_high = data.groupby('Date')['Data_Value'].max()
record_low = data.groupby('Date')['Data_Value'].min()
high2015 = data2015.groupby('Date')['Data_Value'].max()
low2015 = data2015.groupby('Date')['Data_Value'].min()
#
observation_dates = list(range(1,366))
x = np.linspace(1,365,365)
y = np.linspace(1,365,365)
record_high2015 = high2015[high2015 >= record_high.reindex_like(high2015)]
x = [n for n in range(0,365) if (high2015.iloc[n] >= record_high.iloc[n])]
record_low2015 = low2015[low2015 <= record_low.reindex_like(low2015)]
y = [n for n in range(0,365) if (low2015.iloc[n] <= record_low.iloc[n])]
# No record was broken in the year 2015 in the region near Noida, Uttar Pradesh, India
plt.figure(figsize=(12,10))
plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%d$^{\circ}$C'))
ax1 = plt.gca()
ax1.set_title('Highest and Lowest Temperature Records Broken in 2015')
plt.scatter(x,record_high2015,s=100,c='red',zorder=2,alpha=0.7)
plt.scatter(y,record_low2015,s=100,c='blue',zorder=2,alpha=0.7)
plt.yticks(np.arange(-40, max(y), 10))
ax1.fill_between(observation_dates,record_high, record_low, facecolor='gray', alpha=0.5)
for spine in plt.gca().spines.values():
spine.set_visible(False)
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
plt.xticks(np.linspace(0,365,13), months)
ax1.tick_params(axis=u'both', which=u'both',length=0)
plt.show()
plt.savefig('temperature_2005-2015.png')